﻿namespace Sidvall.UI.Entities
{
    public class ChartItemDataValue : BusinessBase
    {
        #region Public Members

        #region Name

        private string _Name = string.Empty;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                value = Sidvall.Business.ValidationManager.GetValidString(value, false, null);
                if (_Name == value)
                    return;
                _Name = value;
                OnPropertyChanged(nameof(Name), true, true);
            }
        }

        #endregion
        #region Value

        private double? _Value;
        public double? Value
        {
            get
            {
                return _Value;
            }
            set
            {
                if (_Value == value)
                    return;
                _Value = value;
                OnPropertyChanged(nameof(Value), true, true);
            }
        }

        #endregion
        #region Category

        private string _Category = string.Empty;
        public string Category
        {
            get
            {
                return _Category;
            }
            set
            {
                value = Sidvall.Business.ValidationManager.GetValidString(value, false, null);
                if (_Category == value)
                    return;
                _Category = value;
                OnPropertyChanged(nameof(Category), true, true);
            }
        }

        #endregion

        #region AcceptChanges

        public void AcceptChanges()
        {
            AcceptChanges(null);
        }
        public void AcceptChanges(Sidvall.Data.AcceptChangesSettings acceptChangesSettings)
        {
            if (this.DataRowStateIsDirty)
            {
                if (acceptChangesSettings == null)
                    acceptChangesSettings = new Sidvall.Data.AcceptChangesSettings();
                Sidvall.Data.EntityManager.AcceptItemChanges(this, acceptChangesSettings);
            }
        }

        #endregion
        #region Copy

        public ChartItemDataValue Copy()
        {
            return Copy(null);
        }
        public ChartItemDataValue Copy(Sidvall.Data.CopySettings copySettings)
        {
            var item = new ChartItemDataValue();
            item.Import(this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(ChartItemDataValue item)
        {
            Import(item, null);
        }
        public void Import(ChartItemDataValue item, Sidvall.Data.CopySettings copySettings)
        {
            if (item == null)
                return;
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (copySettings.FieldCopyOption != Business.FieldCopyOptions.None)
            {
                _Name = item.Name;
                _Value = item.Value;
                _Category = item.Category;
            }
            Sidvall.Data.EntityManager.AfterImportItem(this, item, copySettings);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return this.Name;
        }

        #endregion

        #endregion
        #region Constructors

        public ChartItemDataValue()
        {
        }

        #endregion
    }
}